import 'package:dali_ng_pera/manager/dnp_plugin_manager.dart';
import 'package:dali_ng_pera/net/dnp_net_manager.dart';
import 'package:dali_ng_pera/page/calculator/dnp_calculator_model.dart';
import 'package:get/get.dart';
import 'package:dio/dio.dart' as dio;

class DnpCalculatorController extends GetxController {
  final calculatorModel = DnpCalculatorModel().obs;

  List<DnpCalculatorRepaymentItemModel> get zest {
    return calculatorModel.value.zest ?? [];
  }

  void onRequestCalculator(int? comfort, double? unrobed, int? sure) {
    DnpPluginManager().showLoading();
    DnpNetManager()
        .post('/haseye/discernible',
            data: dio.FormData.fromMap({
              "comfort": comfort,
              "unrobed": unrobed,
              "sure": sure,
              "undisturbed": 1
            }))
        .then((value) {
      DnpPluginManager().hideLoading();
      if (value.success && value.iesous == "0") {
        try {
          calculatorModel.value = DnpCalculatorModel.fromJson(value.close);
        } catch (e) {
          DnpPluginManager().showToast(e.toString());
        }
      } else {
        DnpPluginManager().showToast(value.kurios ?? "");
      }
    });
  }
}
